home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / wait4.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  1KB  |  59 lines

  1. #include "amiga.h"
  2. #include "signals.h"
  3. #include "processes.h"
  4. #include <sys/wait.h>
  5.  
  6. int wait4(int pid, int *statusp, int options, struct rusage *rusage)
  7. {
  8.     struct process *p;
  9.  
  10.     do {
  11.     int seen = FALSE;
  12.  
  13.     scan_processes(p)
  14.         if (pid == 0 || p->pid == pid) {
  15.         seen = TRUE;
  16.  
  17.         if (p->status == exited) {
  18.         int pid = p->pid;
  19.  
  20.         if (statusp)
  21.             *statusp = p->rc;
  22.         _free_entry(p);
  23.  
  24.         return pid;
  25.         }
  26.     }
  27.     if (options & WNOHANG)
  28.         return 0;
  29.     if (!seen) {
  30.         errno = ECHILD;
  31.         return -1;
  32.     }
  33.     _handle_signals(_wait_signals(0));
  34.     } while (1);
  35. }
  36.  
  37. int wait3(int *statusp, int options, struct rusage *rusage)
  38. {
  39.     return wait4(0, statusp, options, rusage);
  40. }
  41.  
  42. int wait(int *statusp)
  43. {
  44.     return wait4(0, statusp, 0, NULL);
  45. }
  46.  
  47. int waitpid(int pid, int *statusp, int options)
  48. {
  49.     /* We have no process groups, so : 
  50.        Our process group encompasses all our children
  51.        Each child is a process group unto itself
  52.        This is somewhat contradictory ... Should this be changed ? */
  53.     if (pid == -1)
  54.     pid = 0;
  55.     if (pid < 0)
  56.     pid = -pid;
  57.     return wait4(pid, statusp, options, NULL);
  58. }
  59.